﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NET4.Database.Repository;

namespace NET4.DataNET4.Repository
{
  public class LeverancierRepository : BaseNET4Repository<Leverancier, LeverancierRepository>, IRepository<Leverancier>
  {
    public LeverancierRepository() : base() { }

    public Leverancier Select(Int32 id)
    {
      return this.Table.Where(l => l.Id == id).First();
    }

    public List<Leverancier> List()
    {
      return this.Table.ToList();
    }

    public void Save(Leverancier leverancier)
    {
      if (leverancier.Id == 0)
      {
        this.Table.InsertOnSubmit(leverancier);
      }

      this.DataContext.SubmitChanges();
    }

    public void Delete(Leverancier leverancier)
    {
      this.Table.DeleteOnSubmit(leverancier);

      this.DataContext.SubmitChanges();
    }

    public IEnumerable<Leverancier> ListByKeyword(String keyword)
    {
      return this.Table.Where(c => c.Naam.Contains(keyword));
    }
  }
}
